package com.wyg.epdata;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import org.junit.Test;

import java.util.Collections;
import java.util.Scanner;

/**
 * @Author: WangYongGan
 * @Date: 2021/11/5 0:48
 * @Description:
 */

//@ConfigurationProperties(prefix = "spring.datasource")@Component@Data
public class GenerateCode {
    public static String module = "epdata";
    public static String classPath = "D:\\project\\ep-parent\\ep-service\\ep-data\\src\\main\\";
    public static String[] tables = new String[]{"article", "article_entity", "article_kw", "company_intro", "company_num", "data_result", "data_result_bio"};


    public static String url = "jdbc:mysql://114.55.253.244:3306/es?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8";
    public static String password = "Wyg1234!";
    public static String username = "root";
    public static String author = "WangYongGan";
    public static String javaPath = classPath + "java//";
    public static String resourcesPath = classPath + "resources//";
    public static String mapperBase = resourcesPath + "mapper//";
    public static String modulePath = "com.wyg." + module;
    public static String fatherPath = null;
    Scanner scanner = new Scanner(System.in);

    @Test
    public void generateCode() {
//        System.out.println("请输入表名:");
//        String[]tables=new String[]{"sys_role_permission","sys_role","sys_user_role","sys_permission"};

//        String table = "sys_role_permission";
//        String table="error_log";
        for (String table : tables) {
            FastAutoGenerator.create(url, username, password)
                    .globalConfig(builder -> {
                        builder.author(author) // 设置作者
                                .enableSwagger() // 开启 swagger 模式
                                .outputDir(javaPath)
//                                .fileOverride()
//                                .disableOpenDir()
                                .dateType(DateType.ONLY_DATE); // 指定输出目录
                    })
                    .packageConfig(builder -> {
                        builder.parent(modulePath) // 设置父包名
//                                .moduleName("system") // 设置父包模块名
                                .pathInfo(Collections.singletonMap(OutputFile.mapperXml, mapperBase)); // 设置mapperXml生成路径
                    })
                    .strategyConfig(builder -> {
                        builder.addInclude(table); // 设置需要生成的表名
                    }).execute();
        }
    }
}
